#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
    int n;
    cin>>n;
    int* nums=new int[n];
    int* res=new int[n];
    for (int i=0;i<n;i++)
    {
        cin>>nums[i];
        res[i]=nums[i];
    }
    sort(res,res+n);

    int first2=0,first3=0;
    for (int i=0;i<n;i++)
    {
        if (res[i]==2)
        {
            first2=i;
            break;
        }
    }
    for (int i=0;i<n;i++)
    {
        if (res[i]==3)
        {
            first3=i;
            break;
        }
    }

    int c12=0,c13=0,c21=0,c23=0,c31=0,c32=0;
    for (int i=0;i<first2;i++)
    {
        if (nums[i]==2)
            c12+=1;
        else if (nums[i]==3)
            c13+=1;
    }
    for (int i=first2;i<first3;i++)
    {
        if (nums[i]==1)
            c21+=1;
        else if (nums[i]==3)
            c23+=1;
    }
    for (int i=first3;i<n;i++)
    {
        if (nums[i]==1)
            c31+=1;
        else if (nums[i]==2)
            c32+=1;
    }

    int sum=0;
    int c1=c12>c21?c21:c12;
    sum+=c1;
    c12-=c1;
    c21-=c1;
    sum+=c13>c31?c31:c13;
    sum+=c23>c32?c32:c23;
    sum+=(c12==0?c21:c12)*2;
    cout<<sum;
}